import type { VbenFormSchema } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { $t } from '#/locales';

import {
  discountFormat,
  remainedCountFormat,
  usePriceFormat,
  validityTypeFormat,
} from '../formatter';

/** 搜索表单的 schema */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'name',
      label: $t('views.mall.promotion.coupon.template.name'),
      componentProps: {
        placeholder: $t('views.mall.promotion.coupon.template.namePlaceholder'),
        allowClear: true,
      },
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeGridProps['columns'] {
  return [
    {
      title: $t('views.mall.promotion.coupon.template.name'),
      field: 'name',
      minWidth: 120,
    },
    {
      title: $t('views.mall.promotion.coupon.send.discount'),
      field: 'discount',
      minWidth: 120,
      formatter: ({ row }) => discountFormat(row),
    },
    {
      title: $t('views.mall.promotion.coupon.send.usePrice'),
      field: 'usePrice',
      minWidth: 100,
      formatter: ({ row }) => usePriceFormat(row),
    },
    {
      title: $t('views.mall.promotion.coupon.send.validityType'),
      field: 'validityType',
      minWidth: 140,
      formatter: ({ row }) => validityTypeFormat(row),
    },
    {
      title: $t('views.mall.promotion.coupon.send.remainedCount'),
      minWidth: 100,
      formatter: ({ row }) => remainedCountFormat(row),
    },
    {
      title: $t('common.action'),
      width: 100,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
